
<!--  /Loading Container -->
<!-- Navbar -->
{include file="public/_head" /}
<!-- /Navbar -->
<!-- Main Container -->
<div class="main-container container-fluid">
    <!-- Page Container -->
    <div class="page-container">

        <!-- Page Sidebar -->
        {include file="public/_left" /}
        <!-- /Page Sidebar -->
        <!-- Page Content -->
        <div class="page-content">
            <!-- Page Breadcrumb -->
            <div class="page-breadcrumbs">
                <ul class="breadcrumb">
                    <li>
                        <i class="fa fa-home"></i>&nbsp;栏目管理
                    </li>
                    <li>栏目列表</li>
                </ul>
            </div>
            <!-- /Page Breadcrumb -->
            <!-- Page Body -->
            <div class="page-body">
                <a href="{:url('admin/cate/add')}" class="btn btn-sm btn-primary"><i class="fa fa-plus"></i>&nbsp;添加栏目</a>
                <div class="row">
                    <div class="col-xs-12">
                        <div class="widget">
                            <div class="widget-header">
                                <span class="widget-caption">添加栏目</span>
                                <div class="widget-buttons">
                                    {$cates->render()|raw|replace}
                                </div>
                            </div>
                            <div class="widget-body">
                                <table class="table table-hover table-bordered">
                                    <thead>
                                    <tr>
                                        <th>排序</th>
                                        <th>文章标题</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    {volist name="cates" id="vo"}
                                    <tr>
                                        <td><input type="text" name="sort" value="{$vo.sort}" dataid="{$vo.id}" size="1"></td>
                                        <td>{$vo.catename}</td>
                                        <td>
                                            <a href="{:url('admin/cate/edit',['id' => $vo.id])}" class="btn btn-sm btn-warning">编辑</a>
                                            <a href="#" class="btn btn-sm btn-danger cat-del" dataid="{$vo.id}">删除</a>
                                        </td>
                                    </tr>
                                    {/volist}
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- /Page Body -->
        </div>
        <!-- /Page Content -->

    </div>
    <!-- /Page Container -->
    <!-- Main Container -->

</div>

{include file="public/_js" /}
<script>
    $(function () {
        $('.pagination').addClass('pagination-sm');

        $('input[name=sort]').change(function () {
            var id = $(this).attr('dataid');
            var sort = $(this).val();
           $.ajax({
              url:"{:url('admin/cate/sort')}",
              type:'post',
              data:{id:id, sort:sort},
              dataType:'json',
              success:function (data) {
                  if (data.code == 1){
                      layer.msg(data.msg,{
                          icon:6,
                          time:2000
                      },function () {
                          location.href = data.url;
                      })
                  }else{
                      layer.open({
                          title:"排序失败",
                          icon:5,
                          anim:6
                      });
                  }
              }
           });
            return false;
        });

        $('.cat-del').click(function () {
            var id = $(this).attr('dataid');
            layer.confirm('确定删除吗？',{
               title:'栏目删除',
                icon:3
            },function (index) {
                layer.close(index);
                $.ajax({
                   url:"{:url('admin/cate/del')}",
                   type:'post',
                   data:{id:id},
                   datatype:'json',
                   success:function(data){
                       if (data.code == 1){
                           layer.msg(data.msg,{
                               icon:6,
                               time:2000
                           },function(){
                              location.href = data.url;
                           });
                       }else{
                           layer.open({
                               title:'删除失败',
                               content:data.msg,
                               icon:6,
                               anim:5
                           })
                       }
                   }
                });
            });
            return false;
        })
    })
</script>
</body>
<!--  /Body -->
</html>
